package com.example.rocketmqspringbootdemo.service.consumer;

import com.alibaba.fastjson.JSONObject;
import com.example.rocketmqspringbootdemo.CommonConstrant;
import com.example.rocketmqspringbootdemo.pojo.User;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;

@Service
@RocketMQMessageListener(topic = CommonConstrant.RocketMQ.OBJECT_TOPIC,
        consumerGroup = CommonConstrant.RocketMQ.OBJECT_CONSUMER_GROUP,
        messageModel = MessageModel.CLUSTERING)
public class UserTopicConsumer implements RocketMQListener<MessageExt> {
    @Override
    public void onMessage(MessageExt message) {
        byte[] body = message.getBody();
        User user = JSONObject.parseObject(body, User.class);
        System.out.println("[Object Topic]received: " + JSONObject.toJSONString(user));
    }
}
